package com.jianyun.jyzs.presenter;

import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter;
import com.jianyun.jyzs.bean.NewSign2Bean;
import com.jianyun.jyzs.bean.Sign2Bean;
import com.jianyun.jyzs.bean.SignNewReslut;
import com.jianyun.jyzs.bean.SignStateBean;
import com.jianyun.jyzs.model.NewSign2Model;
import com.jianyun.jyzs.model.imdoel.INewSign2Model;
import com.jianyun.jyzs.view.iview.INewSign2View;

import java.util.HashMap;
import java.util.List;

/**
 * Created by yangshijun on 2018/8/2.
 */

public class NewSign2Presenter extends MvpBasePresenter<INewSign2View> {

    /**
     * 获取当天的打卡记录
     *
     * @param enterpriseCode
     * @param userId
     * @param date
     */
    public void getSign2List(String enterpriseCode, String userId, String date) {
        if (!isViewAttached()) return;
        NewSign2Model.getInstance().getRecordeByDate(enterpriseCode, userId, date, new INewSign2Model.OnGetRecordListener() {
            @Override
            public void onGetSuccess(List<NewSign2Bean.SignDetail> signDetail) {
                getView().onGetSignListSunccess(signDetail);
            }

            @Override
            public void onFailed(String msg) {
                getView().onFaile(msg);
            }
        });
    }

    /**
     * 打卡
     *
     * @param map
     */
    public void startSign2(HashMap<String, String> map) {
        if (!isViewAttached()) return;
        NewSign2Model.getInstance().newSign2(map, new INewSign2Model.OnNewSignListener() {
            @Override
            public void onSuccess(Sign2Bean newSignReslut) {
                getView().onSignSuccess(newSignReslut);
                getView().hideLoading();
            }

            @Override
            public void onFailed(String msg) {
                getView().hideLoading();
                getView().onFaile(msg);
            }
        });

    }

    /**
     * 更新打卡
     *
     * @param map
     */
    public void updateSign2(HashMap<String, String> map) {
        if (!isViewAttached()) return;
        NewSign2Model.getInstance().updateSign2(map, new INewSign2Model.OnNewSignListener() {
            @Override
            public void onSuccess(Sign2Bean newSignReslut) {
                getView().onSignSuccess(newSignReslut);
                getView().hideLoading();
            }

            @Override
            public void onFailed(String msg) {
                getView().hideLoading();
                getView().onFaile(msg);
            }
        });
    }

    /**
     * 获取用户打卡后的状态
     *
     * @param enterpriseCode
     * @param userId
     * @param signType
     */
    public void getUserSignState(String enterpriseCode, String userId, String signType) {
        if (!isViewAttached()) return;
        NewSign2Model.getInstance().getUserSignState(enterpriseCode, userId, signType, new INewSign2Model.OnGetNowStateListener() {
            @Override
            public void onSuccess(SignStateBean signStateBean) {
                getView().onGetSignState(signStateBean);
            }

            @Override
            public void onFailed(String msg) {
                getView().onFaile(msg);
            }
        });
    }

}
